package cn.iocoder.yudao.module.crossborder.platform.service.platformordermapping;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.crossborder.platform.controller.admin.platformordermapping.vo.*;
import cn.iocoder.yudao.module.crossborder.platform.dal.dataobject.platformordermapping.PlatformOrderMappingDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.crossborder.platform.dal.mysql.platformordermapping.PlatformOrderMappingMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.crossborder.platform.enums.ErrorCodeConstants.*;

/**
 * 跨境电商平台订单映射 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class PlatformOrderMappingServiceImpl implements PlatformOrderMappingService {

    @Resource
    private PlatformOrderMappingMapper platformOrderMappingMapper;

    @Override
    public Long createPlatformOrderMapping(PlatformOrderMappingSaveReqVO createReqVO) {
        // 插入
        PlatformOrderMappingDO platformOrderMapping = BeanUtils.toBean(createReqVO, PlatformOrderMappingDO.class);
        platformOrderMappingMapper.insert(platformOrderMapping);

        // 返回
        return platformOrderMapping.getId();
    }

    @Override
    public void updatePlatformOrderMapping(PlatformOrderMappingSaveReqVO updateReqVO) {
        // 校验存在
        validatePlatformOrderMappingExists(updateReqVO.getId());
        // 更新
        PlatformOrderMappingDO updateObj = BeanUtils.toBean(updateReqVO, PlatformOrderMappingDO.class);
        platformOrderMappingMapper.updateById(updateObj);
    }

    @Override
    public void deletePlatformOrderMapping(Long id) {
        // 校验存在
        validatePlatformOrderMappingExists(id);
        // 删除
        platformOrderMappingMapper.deleteById(id);
    }

    @Override
        public void deletePlatformOrderMappingListByIds(List<Long> ids) {
        // 删除
        platformOrderMappingMapper.deleteByIds(ids);
        }


    private void validatePlatformOrderMappingExists(Long id) {
        if (platformOrderMappingMapper.selectById(id) == null) {
            throw exception(PLATFORM_ORDER_MAPPING_NOT_EXISTS);
        }
    }

    @Override
    public PlatformOrderMappingDO getPlatformOrderMapping(Long id) {
        return platformOrderMappingMapper.selectById(id);
    }

    @Override
    public PageResult<PlatformOrderMappingDO> getPlatformOrderMappingPage(PlatformOrderMappingPageReqVO pageReqVO) {
        return platformOrderMappingMapper.selectPage(pageReqVO);
    }

}